﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using hsgsSHXX.DBUtility;

namespace hsgsSHXX.DAL
{
    /// <summary>
    /// 社会信息资源库 数据类
    /// </summary>
    public class SHXX
    {
        public SHXX()
        {
        }
        public DataSet GetFondListByPage(int pageSize, int pageIndex, string strWhere, string fOrderFiled, out int total)
        {
            if (fOrderFiled == "")
            {
                fOrderFiled = "ID ";
            }
            SqlParameter[] parameters = {  
                    new SqlParameter("@tableName", SqlDbType.VarChar, 50),  
                    new SqlParameter("@fields", SqlDbType.VarChar, 2000),  
                    new SqlParameter("@orderField", SqlDbType.VarChar, 500),  
                    new SqlParameter("@sqlWhere", SqlDbType.VarChar,2000),  
                    new SqlParameter("@pageSize", SqlDbType.Int),  
                    new SqlParameter("@pageIndex", SqlDbType.Int),  
                    new SqlParameter("@TotalPage", SqlDbType.Int),
                    new SqlParameter("@TotalRecordCount", SqlDbType.Int) 
                    };

            parameters[0].Value = "t_SHXX";
            parameters[1].Value = "*";
            parameters[2].Value = fOrderFiled;
            parameters[3].Value = strWhere;
            parameters[4].Value = pageSize;
            parameters[5].Value = pageIndex;
            parameters[6].Direction = ParameterDirection.Output;
            parameters[7].Direction = ParameterDirection.Output;
            DataSet ds = DbHelperSQL.RunProcedure("up_GetRecordByPage", parameters, "ds", 60 * 30);
            total = int.Parse(parameters[7].Value.ToString());
            return ds;

        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public hsgsSHXX.Model.SHXX DataRowToModel(DataRow row)
        {
            hsgsSHXX.Model.SHXX model = new hsgsSHXX.Model.SHXX();
            if (row != null)
            {
                if (row["ID"] != null && row["ID"].ToString() != "")
                {
                    model.ID = decimal.Parse(row["ID"].ToString());
                }
                if (row["SJTGBM"] != null)
                {
                    model.SJTGBM = row["SJTGBM"].ToString();
                }
                if (row["SJLY"] != null)
                {
                    model.SJLY = row["SJLY"].ToString();
                }
                if (row["DRRQ"] != null && row["DRRQ"].ToString() != "")
                {
                    model.DRRQ = DateTime.Parse(row["DRRQ"].ToString());
                }
                if (row["XM"] != null)
                {
                    model.XM = row["XM"].ToString();
                }
                if (row["SFZH"] != null)
                {
                    model.SFZH = row["SFZH"].ToString();
                }
                if (row["LXDH"] != null)
                {
                    model.LXDH = row["LXDH"].ToString();
                }
                if (row["DZ"] != null)
                {
                    model.DZ = row["DZ"].ToString();
                }
                if (row["BZ"] != null)
                {
                    model.BZ = row["BZ"].ToString();
                }
            }
            return model;
        }
    }
}
